import { fileURLToPath, URL } from 'node:url'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    // vueDevTools(), // 注释掉未定义的插件
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [
        ElementPlusResolver({importStyle:"sass"})
      ],
    }),
    // ElementPlus({ // 注释掉未安装的插件
    //   useSource: true,
    // }),
  ],
  server: {
    port: 5050,
    proxy: {
      // 配置代理规则，将所有以 /api 开头的请求代理到后端服务
      '/api/sys': {
        target: 'http://localhost:6005', // 目标接口域名
        changeOrigin: true, // 允许跨域
        rewrite: (path) => path.replace(/^\/api\/sys/, ''), // 重写路径
        secure: false
      },
    },
    // 添加HMR配置解决WebSocket连接问题
    hmr: {
      overlay: true
    },
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
})
